﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Investment : IAccessible<P_Investment, Investment>, ILogicEntity<P_Investment, Investment>
    {
        public int ID { get; set; }
        public string InvestMentCode { get; set; }
        public int OrderID { get; set; }
        public int ProjectId { get; set; }
        public DateTime CreateTime { get; set; }
        public decimal InvestMentAmount { get; set; }
        public PayWay PayWay { get; set; }
        public InvestmentStatus Status { get; set; }
        public string Remark { get; set; }
        public string UserName { get; set; }

        public Project Project { get; set; }

        public Investment LoadProject(P_Project p_project)
        {
            this.Project = new Project().Set(p_project);
            return this;
        }


        protected override void Covariant(P_Investment model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.ID = model.ID;
                this.InvestMentAmount = model.InvestMentAmount;
                this.InvestMentCode = model.InvestMentCode;
                this.OrderID = model.OrderID;
                this.PayWay = (PayWay)model.PayWay;
                this.ProjectId = model.ProjectId;
                this.Remark = model.Remark;
                this.Status = (InvestmentStatus)model.Status;
                this.UserName = model.UserName;
            }
        }

        protected override P_Investment Inverter(Investment model)
        {
            if (model != null)
            {
                return new P_Investment()
                {
                    CreateTime = model.CreateTime,
                    ID = model.ID,
                    InvestMentAmount = model.InvestMentAmount,
                    InvestMentCode = model.InvestMentCode,
                    OrderID = model.OrderID,
                    PayWay = (int)model.PayWay,
                    ProjectId = model.ProjectId,
                    Remark = model.Remark,
                    Status = (int)model.Status,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public Investment Set(P_Investment dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
